package com.fly.demo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@EnableScheduling
@SpringBootApplication
public class SpringbootAdminClientApplication implements CommandLineRunner
{
    /**
     * 监控页面查看地址(注入不成功，默认赋值为空字符串 "")
     */
    @Value("${spring.boot.admin.client.url:}")
    String adminClientUrl;
    
    public static void main(String[] args)
    {
        SpringApplication.run(SpringbootAdminClientApplication.class, args);
    }
    
    @Scheduled(cron = "0/20 * * * * ?")
    public void print()
    {
        log.info("time = {}", System.currentTimeMillis());
    }
    
    @Override
    public void run(String... args)
    {
        try
        {
            if (!"".equals(adminClientUrl))
            {
                Runtime.getRuntime().exec("cmd /c start /min " + adminClientUrl);
            }
        }
        catch (Exception e)
        {
            log.error(e.getMessage(), e.getCause());
        }
    }
}